import { _decorator, Component, Label, Node, ProgressBar, Sprite, SpriteFrame } from 'cc';
import { Long_Mission, MISSION_TYPE } from '../../Cube/Levels';
import DatasSpace from '../Tool/DatasSpace';
const { ccclass, property } = _decorator;

@ccclass('longMissionItem')
export class longMissionItem extends Component {

  @property(Node) rewList: Node = null;
  @property(Sprite) titleSp: Sprite = null;
  @property(ProgressBar) targetProgress: ProgressBar = null;
  @property(SpriteFrame) levelTitleBg: SpriteFrame = null;
  @property(SpriteFrame) videoTitleBg: SpriteFrame = null;

  private missionConfig: any = null;

  protected onEnable(): void {
    this.initLocalData();
  }

  start() {

  }

  update(deltaTime: number) {

  }

  initMission(id) {
    this.missionConfig = Long_Mission[id];
    let rewList = this.missionConfig.rewardList;
    for (let i = 0; i < rewList.length; i++) {
      let rewItem = this.rewList.children[i];
      rewItem.getComponentInChildren(Label).string = rewList[i][1];
      this.titleSp.spriteFrame = this.missionConfig.type == MISSION_TYPE.LEVEL ? this.levelTitleBg : this.videoTitleBg;
      this.initLocalData();
    }
  }

  initLocalData() {
    if (this.missionConfig) {
      let targetNum = this.missionConfig.targetNum;
      let dataNum = DatasSpace.Instance.getInt('LongMission_' + this.missionConfig.type, 0);

      this.targetProgress.node.getComponentInChildren(Label).string = `${dataNum}/${targetNum}`;
    }

  }
}


